<?php
/**
 * Created by PhpStorm.
 * User: CYF
 * Date: 2018/1/28
 * Time: 4:18
 */

namespace Home\Model;
use Think\Model\BaseModel;

class DepartmentModel extends BaseModel{

    protected $_link = array(
        'College' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name' => 'School',
            'foreign_key' => 'sch_id',
            'mapping_fields' => 'sch_name',
            'as_fields' => 'sch_name'
        ),
        'Teacher' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name' => 'Teacher',
            'foreign_key' => 'tea_id',
            'mapping_fields' => 'tea_name',
            'as_fields' => 'tea_name'
        ),
    );
    protected $_scope = array(
        'DepartmentName' => array(
            'field' => array('dept_id','dept_name','sch_id'),
        ),

    );
    public function getCollegeInfoListWithTeacherName($sch_id){
        if ($sch_id == 0) {
            $con['sch_id'] = array('like', "%%");
        } else {
            $con['sch_id'] = $sch_id;
        }
        $info = $this -> where($con)->relation('Teacher') -> select();
        if($info){
            return $info;
        }else{
            return array();
        }
    }

    public function getDepartmentInfoListByAll(){
        $result = $this->select();

        if($result){
            return $result;
        }else{
            return array();
        }

    }



    public function getCollegeAndDepartmentName($dept_id){

        $info = $this-> where(array('dept_id'=> $dept_id))->relation('College')->scope('DepartmentName')->find();
        if (!$info){
            return false;
        }
        return $info;
    }


}